package com.tao.controller;

import com.tao.service.MiaoshaService;
import com.tao.service.impl.Mq.MiaoshaSendService;
import com.tao.service.impl.Mq.SubmitSendMqService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: alubus
 * @Date: 2021/11/15 18:00
 * @Package: com.tao.controller
 */
@RestController

public class TestMiaoshaController {
    Logger logger = LoggerFactory.getLogger(getClass());


    @Autowired
    MiaoshaService miaoshaServiceImpl;

    @Autowired
    MiaoshaSendService miaoshaSendService;

    @Autowired
    SubmitSendMqService submitSendMqService;

    //发送秒杀请求  通过qid
    @RequestMapping("/miaosha/{id}")
    public int reduceone3(@PathVariable("id") Long id){
        miaoshaSendService.sendTest();
        return 666;
    }
    //    重置 666 的秒杀数据 为  20
    @RequestMapping("/resetMiaosha")
    public String resetMiaosha(){
        miaoshaServiceImpl.setMiashaSum(666L,20);
        return "success";
    }

    // 减少一件  id: 666 的库存
    @RequestMapping("/reduceone")
    public int reduceone1_1(){
        int i = miaoshaServiceImpl.reduceMiaoshaSumOne(666L);
        return i;
    }

    //减少一个  id 的一键库存
    @RequestMapping("/reduceone/{id}")
    public int reduceone1(@PathVariable("id") Long id){
//        logger.info("id:"+id+"  商品-1");
        int i = miaoshaServiceImpl.reduceMiaoshaSum(id,1);
        return i;
    }


    @RequestMapping("/DDLTest")
    public void sixinTest(){
        submitSendMqService.sendMessage("死信队列 测试测试");
    }

}
